package com.beiye.drivertransport.prejobtraining;

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.SubActivity.SignActivity;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.adapter.ListBaseAdapter;
import com.beiye.drivertransport.adapter.SuperViewHolder;
import com.beiye.drivertransport.bean.CheckBean;
import com.beiye.drivertransport.bean.DailyPriceBean;
import com.beiye.drivertransport.bean.JobCompleBean;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.bean.SpecifiedLearnIngHomeBean;
import com.beiye.drivertransport.bean.TrainingIndvPriceFindBean;
import com.beiye.drivertransport.bean.UserVipCheckBean;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.utils.HelpUtil;
import com.beiye.drivertransport.utils.TiShiDialog;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.githang.statusbar.StatusBarCompat;
import com.github.jdsjlzx.interfaces.OnLoadMoreListener;
import com.github.jdsjlzx.interfaces.OnRefreshListener;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;

import java.util.List;


import okhttp3.Call;
import okhttp3.Response;

//岗前培训计划列表
public class SubPreJobTrainingActivity extends TwoBaseAty {
    //  private PopWindowApt popWindowApt;
//    @Bind(R.id.tv_job)
//    TextView tv_job;

    ImageView tv_comple;
    //    @Bind(R.id.img_job)
//    TextView img_job;

    RelativeLayout re_comple;

    LRecyclerView lv_job;

    TextView tv_goumai;
    private int firstIndex = 1;
    private int pageSize = 10;
    private LRecyclerViewAdapter lRecyclerViewAdapter1;
    private PrejobLearningHomeApt prejobLearningHomeApt;
    private boolean checkResult;
    private boolean buyMember;
    //    private PopupWindow mPopWindow;
//    private PreJobTrainingRecycleradatper preJobTrainingRecycleradatper;
//    private LRecyclerViewAdapter lRecyclerViewAdapter1;
    //   ArrayList<LoginUserBean.DataBean.CurUserOrgBean> cusList = new ArrayList<>();
//    private MyExpandableListViewAdapter adapter;
//    private List<PreJobTrainingBean.RowsBean> ParentList = new ArrayList<>();
//    Map<PreJobTrainingBean.RowsBean, List<PreJobTrainingBean.RowsBean.ListCourseBean>> dataset = new HashMap<>();
//    ArrayList<PreJobTrainingBean.RowsBean.ListCourseBean> pbcourselist=new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.activity_sub_pre_job_training;
    }

    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.img_jobback) {
            SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor edit = sp.edit();
            edit.clear();
            edit.commit();
            finish();
        } else if (id == R.id.tv_goumai) {
            if (Utils.isFastClicker()) {
                return;
            }

            SharedPreferences sp1 = getSharedPreferences("SubPreJobTrainingActivity",
                    Context.MODE_PRIVATE);
            String orgId = sp1.getString("orgId", "");
            float pjtPrice = sp1.getFloat("pjtPrice", 0);
            float balance = sp1.getFloat("balance", 0);

            if (checkResult) {
                pjtPrice = 0f;
            }

            if (pjtPrice == 0)//岗前培训免费
            {
                showLoadingDialog("");
                LoginUserBean userInfo = UserManger.getUserInfo();
                LoginUserBean.DataBean data = userInfo.getData();
                String userId = data.getUserId();
                new Login().getprejobPayMentApp(userId, orgId, this, 4);
            } else if (pjtPrice > 0) {
                Bundle bundle = new Bundle();
                bundle.putString("orgId", orgId);
                bundle.putFloat("pjtPrice", pjtPrice);
                bundle.putFloat("balance", balance);
                startActivity(PrejobPaymentActivity.class, bundle);
                    /*if(buyMember){
                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubPreJobTrainingActivity.this);
                        builder1.setMessage("您所属企业需购买包月会员");
                        builder1.setTitle("提示:");
                        builder1.setPositiveButton("买会员", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                //startActivity(MemberInfoActivity.class, null);
                                startActivity(MemberMsgActivity.class,null);
                            }
                        });
                        builder1.create().show();
                    }else{

                    }*/
            }
        }

    }

    @Override
    public void initData() {
        tv_comple = (ImageView) findViewById(R.id.tv_job2);
        re_comple = (RelativeLayout) findViewById(R.id.re_job);
        lv_job = (LRecyclerView) findViewById(R.id.listview_message);
        tv_goumai = (TextView) findViewById(R.id.tv_goumai);
        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#1F80C4"));
        initUi();
    }

    private void initUi() {
//        lv_job = (ExpandableListView) findViewById(R.id.lv_job);
//        lv_job.setGroupIndicator(null);//去掉箭头
//        lv_job.setEmptyView(empty_view);
//        lv_job.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
//            @Override
//            public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition, int childPosition, long l) {
//                SharedPreferences sp1 = getSharedPreferences("Mark6", Context.MODE_PRIVATE);
//                int mark = sp1.getInt("Mark", 1);
//                if(mark==0)
//                {
//                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubPreJobTrainingActivity.this);
//                    builder1.setMessage("您已被企业管理员禁用,请联系企业管理员");
//                    builder1.setTitle("提示:");
//                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
//                        public void onClick(DialogInterface dialog, int which) {
//                            dialog.dismiss();
//                            //设置你的操作事项
//                        }
//                    });
//                    builder1.create().show();
//
//                }else{
//                    if(!CameraCanUseUtils.isCameraCanUse()) {
//
//                        ToastUtil.showShortToast(SubPreJobTrainingActivity.this,"请到手机设置界面里找驾运宝允许开启照相");
//
//                    }else{
//                        if(dataset.get(ParentList.get(groupPosition)).get(childPosition).getStudyState()==0)
//                        {
//                            showLoadingDialog("正在加载");
//                            //校验是否学过课程
//                            int tcSn = dataset.get(ParentList.get(groupPosition)).get(childPosition).getTcSn();
//                            int otcSn = dataset.get(ParentList.get(groupPosition)).get(childPosition).getSn();
//                            List<PreJobTrainingBean.RowsBean.ListCourseBean> listCourse = ParentList.get(groupPosition).getListCourse();
//                            pbcourselist.clear();
//                            for (int i = 0; i < listCourse.size(); i++) {
//                                if (listCourse.get(i).getSn() != otcSn&&listCourse.get(i).getStudyState()!=1) {
//                                    pbcourselist.add(listCourse.get(i));
//                                }
//                            }
//                            Bundle bundle = new Bundle();
//                            bundle.putInt("tcsn", tcSn);
//                            bundle.putInt("otcSn", otcSn);
//                            //存储一份orgId文件
//                            SharedPreferences sppp = getSharedPreferences("orgId2",
//                                    Context.MODE_PRIVATE);
//                            String  orgId = sppp.getString("orgId","");
//                            int pjtMinPer = sppp.getInt("pjtMinPer", 0);
//                            bundle.putString("orgId",orgId);
//                            bundle.putInt("pjtMinPer",pjtMinPer);
//                            bundle.putSerializable("pbcourselist", (Serializable) pbcourselist);
//                            startActivity(PreJobCourseDetailsActivity.class, bundle);
//                        }else if(dataset.get(ParentList.get(groupPosition)).get(childPosition).getStudyState()==1)
//                        {
//                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubPreJobTrainingActivity.this);
//                            builder1.setMessage("该课程已学习");
//                            builder1.setTitle("提示:");
//                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
//                                public void onClick(DialogInterface dialog, int which) {
//                                    dialog.dismiss();
//                                    ;
//                                    //设置你的操作事项
//                                }
//                            });
//                            builder1.create().show();
//                        }
//                    }
//                }
//
//                return true;
//            }
//        });
        LinearLayoutManager ms = new LinearLayoutManager(this);
        ms.setOrientation(LinearLayoutManager.VERTICAL);
        lv_job.setLayoutManager(ms);
        prejobLearningHomeApt = new PrejobLearningHomeApt(SubPreJobTrainingActivity.this);
        lRecyclerViewAdapter1 = new LRecyclerViewAdapter(prejobLearningHomeApt);
        lv_job.setAdapter(lRecyclerViewAdapter1);
        lv_job.setFooterViewColor(R.color.colorAccent, R.color.dark, android.R.color.white);
        lv_job.setFooterViewHint("拼命加载中", "已经全部为你呈现了", "网络不给力啊，点击再试一次吧");
        lv_job.setOnRefreshListener(new OnRefreshListener() {

            @Override
            public void onRefresh() {
                firstIndex = 1;
                requestData();
            }
        });

        lv_job.setOnLoadMoreListener(new OnLoadMoreListener() {

            @Override
            public void onLoadMore() {
                firstIndex += pageSize;
                requestData();
            }
        });
//        empty_view.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                lv_job.refresh();
//            }
//        });
        lv_job.refresh();
//        lRecyclerViewAdapter1.setOnItemClickListener(new com.github.jdsjlzx.interfaces.OnItemClickListener() {
//            @Override
//            public void onItemClick(View view, int position) {
//                if (Utils.isFastDoubleClick()) {
//                    return ;
//                }
//                SharedPreferences sp1 = getSharedPreferences("SubPreJobTrainingActivity", Context.MODE_PRIVATE);
//                int mark = sp1.getInt("Mark", 1);
//                if(mark==0)
//                {
//                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubPreJobTrainingActivity.this);
//                    builder1.setMessage("您已被企业管理员禁用,请联系企业管理员");
//                    builder1.setTitle("提示:");
//                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
//                        public void onClick(DialogInterface dialog, int which) {
//                            dialog.dismiss();
//                            //设置你的操作事项
//                        }
//                    });
//                    builder1.create().show();
//                    return;
//                }
//
//
//                    if(!CameraCanUseUtils.isCameraCanUse()) {
//
//                        ToastUtil.showShortToast(SubPreJobTrainingActivity.this,"请到手机设置界面里找驾运宝允许开启照相");
//                        return;
//                    }else{
//                    if(preJobTrainingRecycleradatper.getDataList().get(position).getStudyState()==0)
//                    {
//                        showLoadingDialog("正在加载");
//                        //校验是否学过课程
//                        int tcSn = preJobTrainingRecycleradatper.getDataList().get(position).getTcSn();
//                        int otcSn = preJobTrainingRecycleradatper.getDataList().get(position).getSn();
//                            Bundle bundle = new Bundle();
//                            bundle.putInt("tcsn", tcSn);
//                            bundle.putInt("otcSn", otcSn);
//                            //存储一份orgId文件
//                            SharedPreferences sppp = getSharedPreferences("orgId2",
//                                    Context.MODE_PRIVATE);
//                            String  orgId = sppp.getString("orgId","");
//                            int minPer = sppp.getInt("minPer", 0);
//                            bundle.putString("orgId",orgId);
//                            bundle.putInt("minPer",minPer);
//                            startActivity(PreJobCourseDetailsActivity.class, bundle);
//                    }else if(preJobTrainingRecycleradatper.getDataList().get(position).getStudyState()==1)
//                    {
//                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(SubPreJobTrainingActivity.this);
//                        builder1.setMessage("该课程已学习");
//                        builder1.setTitle("提示:");
//                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
//                            public void onClick(DialogInterface dialog, int which) {
//                                dialog.dismiss();
//                                ;
//                                //设置你的操作事项
//                            }
//                        });
//                        builder1.create().show();
//                    }
//                }
//
//        });

    }

    @Override
    public void onBackPressed() {
        SharedPreferences spp = getSharedPreferences("SubPreJobTrainingActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = spp.edit();
        edit.clear();
        edit.commit();
        super.onBackPressed();
    }


    //    //校验岗前培训课程是否学过
//    private void initcoursesupermaketCheckData(int tcSn , int otcSn) {
//        LoginUserBean userInfo = UserManger.getUserInfo();
//        String userId = userInfo.getData().getUserId();
//        //存储一份readInterval文件
//        SharedPreferences sp = getSharedPreferences("readInterval",
//                Context.MODE_PRIVATE);
//        int readInterval = sp.getInt("readInterval", 0);
//        //存储一份tcSn文件
//        SharedPreferences spp = getSharedPreferences("prejobTraingtcSn",
//                Context.MODE_PRIVATE);
//        SharedPreferences.Editor editor = spp.edit();
//        editor.putInt("tcSn", tcSn);
//        editor.putInt("otcSn",otcSn);
//        editor.commit();
//        dialog = CustomProgressDialog.show(SubPreJobTrainingActivity.this, "", true, null);
//        new Login().getPreJobTrainingandcoursesupermaketCheck(userId, tcSn, readInterval, this, 2);
//
//    }


//    private void showPopupWindow() {
//        //设置contentView
//        View contentView = LayoutInflater.from(SubPreJobTrainingActivity.this).inflate(R.layout.popwindow_layout, null);
//        mPopWindow = new PopupWindow(contentView,
//                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
//        //设置各个控件的点击响应
//        ListView lv_company = (ListView) contentView.findViewById(R.id.lv_company);
//        lv_company.setAdapter(popWindowApt);
//           mPopWindow.showAtLocation(tv_job, Gravity.CENTER, 0, 0);
//
//        lv_company.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
//                if (popWindowApt != null) {
//
//                    String orgName = popWindowApt.getItem(position).getOrgName();
//                    String orgId = popWindowApt.getItem(position).getOrgId();
//
//                    int pjtMinPer = popWindowApt.getItem(position).getPjtMinPer();
//                    int readInterval = popWindowApt.getItem(position).getReadInterval();
//                    int mark = popWindowApt.getItem(position).getMark();
//                    mPopWindow.dismiss();
//                    tv_job.setText(orgName);
//
//
//                    //存储一份readInterval文件
//                    SharedPreferences sp = getSharedPreferences("orgId2",
//                     Context.MODE_PRIVATE);
//                    SharedPreferences.Editor editor = sp.edit();
//                    editor.putString("orgId", orgId);
//                    editor.putInt("pjtMinPer",pjtMinPer);
//                    editor.commit();
//                    //存储一份readInterval文件
//                    SharedPreferences spp = getSharedPreferences("readInterval6",
//                            Context.MODE_PRIVATE);
//                    SharedPreferences.Editor editor1 = spp.edit();
//                    editor1.putInt("readInterval", readInterval);
//                    editor1.commit();
//                    SharedPreferences sppp = getSharedPreferences("Mark6", Context.MODE_PRIVATE);
//                    SharedPreferences.Editor editor2 = sppp.edit();
//                    editor2.putInt("Mark", mark);
//                    editor2.commit();
//
//                    initUiData(orgId, readInterval);
//
//                }
//            }
//        });
//    }

//    //进入岗前培训时界面前调一下接口
//    public void readintervalData(String adId) {
//
//        OkGo.get(AppInterfaceConfig.BASE_URL + "sys/config/query/" + adId)     // 请求方式和请求url
//                .tag(this)                       // 请求的 tag, 主要用于取消对应的请求
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(String result, Call call, Response response) {
//
//                        ReadIntervalBean readIntervalBean = JSON.parseObject(result, ReadIntervalBean.class);
//
//                        ReadIntervalBean.DataBean data = readIntervalBean.getData();
//                        int readInterval = data.getReadInterval();
//                        //存储一份readInterval文件
//                        SharedPreferences sp = getSharedPreferences("readInterval",
//                                Context.MODE_PRIVATE);
//                        SharedPreferences.Editor editor = sp.edit();
//                        editor.putInt("readInterval", readInterval);
//                        editor.commit();
//                    }
//                });
//    }

    @Override
    protected void onResume() {
        super.onResume();
        lv_job.refresh();
        requestData();
    }


    public void requestData() {

        Bundle bundle = getIntent().getExtras();
        int pjtMinPer = bundle.getInt("pjtMinPer");
        int mark = bundle.getInt("Mark");
        String orgId = bundle.getString("orgId");
        String forbidHour = bundle.getString("forbidHour");
        int faceRecgMark = bundle.getInt("faceRecgMark");
        int signMark = bundle.getInt("signMark");
        String photoUrl = bundle.getString("personphotoUrl");
        //存储一份readInterval文件
        SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("orgId", orgId);
        editor.putString("forbidHour", forbidHour);
        editor.putString("photoUrl", photoUrl);
        editor.putInt("pjtMinPer", pjtMinPer);
        editor.putInt("Mark", mark);
        editor.putInt("signMark", signMark);
        editor.putInt("faceRecgMark", faceRecgMark);
        editor.commit();
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();

        new Login().getPreJobTrainingandComple(userId, orgId, this, 2);
        new Login().getUserpjobtraining(orgId, userId, this, 3);
        showLoadingDialog("正在加载");
        new Login().getSpecifiedLearningTwo(orgId, userId, 1, 1, firstIndex, pageSize, this, 1);

        //new Login().userVipCheck(userId,orgId,this,5); //会员是否到期

        //new Login().trainingIndvPriceFind(orgId, SubPreJobTrainingActivity.this, 6); //获取会员方案列表
    }



    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        super.onSuccess(result, call, response, what);

        if (what == 1) {
            dismissLoadingDialog();
//            List<PreJobTrainingBean.RowsBean> rows = preJobTrainingBean.getRows();
//            ParentList.clear();
//            dataset.clear();
//            ParentList.addAll(rows);
//            for (int i = 0; i < ParentList.size(); i++) {
//                List<PreJobTrainingBean.RowsBean.ListCourseBean> listCourse = ParentList.get(i).getListCourse();
//                dataset.put(ParentList.get(i), listCourse);
//            }
//            adapter = new MyExpandableListViewAdapter(SubPreJobTrainingActivity.this, ParentList, dataset);
//            lv_job.setAdapter(adapter);
            SpecifiedLearnIngHomeBean specifiedLearnIngHomeBean = JSON.parseObject(result, SpecifiedLearnIngHomeBean.class);
            if (specifiedLearnIngHomeBean != null) {
                try {

                    if (specifiedLearnIngHomeBean.getRows() != null && specifiedLearnIngHomeBean.getRows().size() > 0) {
                        lv_job.setVisibility(View.VISIBLE);
                        if (firstIndex == 1) {
                            prejobLearningHomeApt.clear();
                            prejobLearningHomeApt.setDataList(specifiedLearnIngHomeBean.getRows());
                        } else {
                            prejobLearningHomeApt.addAll(specifiedLearnIngHomeBean.getRows());
                        }

                        if (specifiedLearnIngHomeBean.getRows().size() < pageSize) {
                            lv_job.setNoMore(true);
                        }
                    } else {
                        if (firstIndex == 1) {//第一页
                            lv_job.setEmptyView(tv_goumai);
                            prejobLearningHomeApt.clear();
                        } else {
                            lv_job.setNoMore(true);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                lv_job.refreshComplete(specifiedLearnIngHomeBean.getRows() == null ? 0 : specifiedLearnIngHomeBean.getRows().size());
                lRecyclerViewAdapter1.notifyDataSetChanged();
            }


//        else if (what == 2) {
//
//            if(!CameraCanUseUtils.isCameraCanUse()) {
//                dialog.dismiss();
//               ToastUtil.showShortToast(SubPreJobTrainingActivity.this,"请到手机设置界面里找驾运宝允许开启照相");
//                return;
//            }
//            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
//            int code = checkBean.getCode();
//            String msg = checkBean.getMsg();
//            if (code == 0) {
//
//                //存储一份文件
//                SharedPreferences spp = getSharedPreferences("prejobTraingtcSn",
//                        Context.MODE_PRIVATE);
//                int tcSn = spp.getInt("tcSn", 0);
//                int otcSn = spp.getInt("otcSn", 0);
//                Bundle bundle = new Bundle();
//                bundle.putInt("tcsn", tcSn);
//                bundle.putInt("otcSn", otcSn);
////                SharedPreferences sp = getSharedPreferences("readInterval",
////                        Context.MODE_PRIVATE);
////                int readInterval = sp.getInt("readInterval", 0);
////                bundle.putInt("readInterval", readInterval);
//                //存储一份orgId文件
//                SharedPreferences sppp = getSharedPreferences("orgId2",
//                        Context.MODE_PRIVATE);
//                String  orgId = sppp.getString("orgId","");
//                int minPer = sppp.getInt("minPer", 0);
//                bundle.putString("orgId",orgId);
//                bundle.putInt("minPer",minPer);
//                startActivity(PreJobCourseDetailsActivity.class, bundle);
//          //      Toast.makeText(SubPreJobTrainingActivity.this,tcSn+"",Toast.LENGTH_SHORT).show();
//                  dialog.dismiss();
//            }
//        }
        } else if (what == 2) {
            JobCompleBean jobCompleBean = JSON.parseObject(result, JobCompleBean.class);
            int data = jobCompleBean.getData();

            if (data == 1) {
                re_comple.setVisibility(View.VISIBLE);
                tv_comple.setImageResource(R.mipmap.bj_11);
            } else if (data == 0) {
                re_comple.setVisibility(View.VISIBLE);
                tv_comple.setImageResource(R.mipmap.bj_23);

            }

        } else if (what == 3) {
            DailyPriceBean mineUseBean = JSON.parseObject(result, DailyPriceBean.class);
            DailyPriceBean.DataBean dailydata = mineUseBean.getData();
            float balance = dailydata.getBalance();
            float pjtPrice = dailydata.getPjtPrice();
            SharedPreferences sp1 = getSharedPreferences("SubPreJobTrainingActivity",
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor edit = sp1.edit();
            edit.putFloat("balance", balance);
            edit.putFloat("pjtPrice", pjtPrice);
            edit.commit();

        } else if (what == 4) {
            dismissLoadingDialog();
            lv_job.refresh();
            requestData();
        }else  if(what == 5 ){
            UserVipCheckBean bean = JSON.parseObject(result, UserVipCheckBean.class);
            checkResult = bean.isResult();
        }else if(what == 6){
            TrainingIndvPriceFindBean bean = JSON.parseObject(result, TrainingIndvPriceFindBean.class);
            List<TrainingIndvPriceFindBean.RowsBean> rowsBeans = bean.getRows();
            if(rowsBeans==null || rowsBeans.size()<=0){
                buyMember=false;
            }else{
                buyMember=true;
            }
        }
    }

    @Override
    public void onError(String result, Call call, Response response, int what) {
        super.onError(result, call, response, what);
        if (what == 2) {
            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);

            if (checkBean.isResult() == false) {
                re_comple.setVisibility(View.GONE);
            }
        } else if (what == 4) {
            dismissLoadingDialog();
            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
            String msg = checkBean.getMsg();
            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
            builder1.setMessage(msg);
            builder1.setTitle("提示:");
            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    ;
                    //设置你的操作事项
                }
            });
            builder1.create().show();
        }else if(what ==5){
            UserVipCheckBean bean = JSON.parseObject(result, UserVipCheckBean.class);
            checkResult = bean.isResult();
        }

    }


//    private class MyExpandableListViewAdapter extends BaseExpandableListAdapter {
//
//        private Context context;
//        private List<PreJobTrainingBean.RowsBean> ParentList;
//        private Map<PreJobTrainingBean.RowsBean, List<PreJobTrainingBean.RowsBean.ListCourseBean>> dataset;
//
//        public MyExpandableListViewAdapter(Context context, List<PreJobTrainingBean.RowsBean> ParentList, Map<PreJobTrainingBean.RowsBean, List<PreJobTrainingBean.RowsBean.ListCourseBean>> dataset) {
//            this.context = context;
//            this.ParentList = ParentList;
//            this.dataset = dataset;
//        }
//
//
//        //  获得某个父项的某个子项
//        @Override
//        public Object getChild(int parentPos, int childPos) {
//
//            return dataset.get(ParentList.get(parentPos)).get(childPos);
//
//        }
//
//        //  获得父项的数量
//        @Override
//        public int getGroupCount() {
//            return dataset.size();
//        }
//
//         //  获得某个父项的子项数目
//         @Override
//         public int getChildrenCount(int parentPos) {
//         return dataset.get(ParentList.get(parentPos)).size();
//        }
//
//        //  获得某个父项
//        @Override
//        public Object getGroup(int parentPos) {
//            return dataset.get(ParentList.get(parentPos));
//        }
//
//        //  获得某个父项的id
//        @Override
//        public long getGroupId(int parentPos) {
//            return parentPos;
//        }
//
//        //  获得某个父项的某个子项的id
//        @Override
//        public long getChildId(int parentPos, int childPos) {
//            return childPos;
//        }
//
//        //  按函数的名字来理解应该是是否具有稳定的id，这个方法目前一直都是返回false，没有去改动过
//        @Override
//        public boolean hasStableIds() {
//            return false;
//        }
//
//        //  获得父项显示的view
//        @Override
//        public View getGroupView(int parentPos, boolean b, View view, ViewGroup viewGroup) {
//            if (view == null) {
//                LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//                view = inflater.inflate(R.layout.parent_prejob_item, null);
//            }
//            view.setTag(R.layout.parent_prejob_item, parentPos);
//            view.setTag(R.layout.child_prejob_item, -1);
//
//            ImageView img_parent = (ImageView) view.findViewById(R.id.img_parent);
//            TextView parent_line = (TextView) view.findViewById(R.id.parent_line);
//            TextView tv_title = (TextView) view.findViewById(R.id.tv_parent);
//            LinearLayout re_nodata =(LinearLayout) view.findViewById(R.id.re_nodata);//子类无数据
//            if (ParentList != null && parentPos < ParentList.size()) {
//                tv_title.setText(ParentList.get(parentPos).getPlanName());
//
//         //       LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) parent_line.getLayoutParams(); //取控件textView当前的布局参数
//                if (b)//判断展开
//                {
//                        if (ParentList.get(parentPos).getListCourse().size() == 0) {
//                            re_nodata.setVisibility(View.VISIBLE);
//
//                        }
//
//                    img_parent.setImageResource(R.mipmap.jianhao);
////                    linearParams.height = 3;// 控件的高强制设成3
////                    parent_line.setLayoutParams(linearParams);
//                    parent_line.setVisibility(View.GONE);
//                } else {
//                    re_nodata.setVisibility(View.GONE);
//                    img_parent.setImageResource(R.mipmap.jiahao);
////                    linearParams.height = 13;// 控件的高强制设成16
////                    parent_line.setLayoutParams(linearParams);
//                    parent_line.setVisibility(View.VISIBLE);
//                }
//            }
//
//
//            return view;
//        }
//
//        //  获得子项显示的view
//        @Override
//        public View getChildView(int parentPos, int childPos, boolean b, View view, ViewGroup viewGroup) {
//            if (view == null) {
//                LayoutInflater inflater = (LayoutInflater)
//                        getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//                view = inflater.inflate(R.layout.child_prejob_item, null);
//            }
//            view.setTag(R.layout.parent_prejob_item, parentPos);
//            view.setTag(R.layout.child_prejob_item, childPos);
//
//            ImageView img_course = (ImageView) view.findViewById(R.id.img_course);
//            TextView tv_title =(TextView) view.findViewById(R.id.tv_course);
//            TextView tv_coursetime =(TextView) view.findViewById(R.id.tv_course2);
//            ImageView tv_courseno =(ImageView) view.findViewById(R.id.tv_course5);
//
//            tv_title.setText(dataset.get(ParentList.get(parentPos)).get(childPos).getCourseName());
//            tv_coursetime.setText("课程时长:"+dataset.get(ParentList.get(parentPos)).get(childPos).getCourseLength()+"分");
//            if(dataset.get(ParentList.get(parentPos)).get(childPos).getStudyState()==0)
//            {
//                tv_courseno.setImageResource(R.mipmap.wxx);
//                img_course.setImageResource(R.mipmap.icon_kccs_03);
//            }else if(dataset.get(ParentList.get(parentPos)).get(childPos).getStudyState()==1)
//            {
//                tv_courseno.setImageResource(R.mipmap.yxx);
//                img_course.setImageResource(R.mipmap.icon_kccs_06);
//            }
//
//
//
//
//            return view;
//        }


//        //  子项是否可选中，如果需要设置子项的点击事件，需要返回true
//        @Override
//        public boolean isChildSelectable(int i, int i1) {
//            return true;
//        }
//    }

    public class PrejobLearningHomeApt extends ListBaseAdapter<SpecifiedLearnIngHomeBean.RowsBean> {
        protected Context context = null;

        public PrejobLearningHomeApt(Context context) {
            super(context);
            this.context = context;
        }

        @Override
        public int getLayoutId() {
            return R.layout.specifiedlearning_item_layout;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, final int position) {
            final SpecifiedLearnIngHomeBean.RowsBean rowsBean = getDataList().get(position);

            TextView tv_chNo = holder.getView(R.id.tv_chNo);
            TextView tv_title = holder.getView(R.id.tv_title);
            TextView tv_yes = holder.getView(R.id.tv_parent4);//完成情况
            TextView tv_sign = holder.getView(R.id.tv_parent8);//签名情况
            TextView tv_check = holder.getView(R.id.tv_parent5);//审核情况
            TextView tv_Spotcheck = holder.getView(R.id.tv_parent7);//抽查情况
            TextView tv_actualChLength = holder.getView(R.id.tv_time);//实际学习时间
            // TextView tv_setChLength =  holder.getView(R.id.tv_time1);//计划学习时间
            TextView tv_line_specified = holder.getView(R.id.tv_line_specified);
            //   ImageView img_share =  holder.getView(R.id.img_share);
            RelativeLayout re_specified1 = holder.getView(R.id.re_specified1);
            final String chName = rowsBean.getChName();
            re_specified1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (Utils.isFastClicker()) {
                        return;
                    }
                    SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                            Context.MODE_PRIVATE);

                    int signMark = sp.getInt("signMark", 0);
                    int Mark = sp.getInt("Mark", 0);
                    int pjtMinPer = sp.getInt("pjtMinPer", 0);
                    String orgId = sp.getString("orgId", "");
                    String forbidHour = sp.getString("forbidHour", "");
                    int faceRecgMark = sp.getInt("faceRecgMark", 0);
                    String photoUrl = sp.getString("photoUrl", "");
                    int sn = rowsBean.getSn();
                    int otpSn = HelpUtil.judgeIntNull(rowsBean.getOtpSn());
                    int actualChLength = rowsBean.getActualChLength();

                    int setChLength = 0;
                    setChLength=(rowsBean.getMiNo()>rowsBean.getSetChLength())?rowsBean.getMiNo():rowsBean.getSetChLength();
                    int checkMark = rowsBean.getCheckMark();
                    int finishMark = rowsBean.getFinishMark();
                    int chNo = rowsBean.getChNo();
                    Bundle bundle = new Bundle();
                    bundle.putInt("Mark", Mark);
                    bundle.putInt("pjtMinPer", pjtMinPer);
                    bundle.putString("orgId", orgId);
                    bundle.putInt("sn", sn);
                    bundle.putInt("otpSn", otpSn);
                    bundle.putString("chName", chName);
                    bundle.putString("forbidHour", forbidHour);
                    bundle.putInt("actualChLength", actualChLength);
                    bundle.putInt("setChLength", setChLength);
                    bundle.putInt("chNo", chNo);
                    bundle.putInt("signMark", signMark);
                    bundle.putInt("checkMark", checkMark);
                    bundle.putInt("finishMark", finishMark);
                    bundle.putInt("faceRecgMark", faceRecgMark);
                    bundle.putString("photoUrl", photoUrl);
                    startActivity(ChildPreJobTrainingActivity.class, bundle);

                }
            });
            final TextView tv_specified_learning = holder.getView(R.id.tv_specified_learning);//学习/签名
            int chNo = rowsBean.getChNo();
            if (chNo == 0) {
                tv_chNo.setText("学时");
            } else {
                tv_chNo.setText(chNo + "学时");
            }
            if (chName == null) {
                tv_title.setText("");
            } else {
                tv_title.setText(chName);
            }
            int finishMark = rowsBean.getFinishMark();
            if (finishMark == 0) {//未完成
                int actualChLength = rowsBean.getActualChLength();
                int setChLength = 0;
                            setChLength=(rowsBean.getMiNo()>rowsBean.getSetChLength())?rowsBean.getMiNo():rowsBean.getSetChLength();
                if (actualChLength == 0 || setChLength == 0) {
                    tv_actualChLength.setText("0%");
                    tv_actualChLength.setTextColor(SubPreJobTrainingActivity.this.getResources().getColor(R.color.bixue_red));
                } else {
                    float studyper = (float) actualChLength / (float) setChLength;
                    if (studyper < 1) {
                        int studyper1 = (int) (studyper * 100);
                        //  String ss = String.format("%1.2f", studyper1);
                        tv_actualChLength.setText(studyper1 + "%");
                        tv_actualChLength.setTextColor(SubPreJobTrainingActivity.this.getResources().getColor(R.color.bixue_red));
                    } else {
                        // int studyper1 = (int) (studyper * 100);
                        // String ss = String.format("%1.2f", studyper1);
                        tv_actualChLength.setText(99 + "%");
                        tv_actualChLength.setTextColor(SubPreJobTrainingActivity.this.getResources().getColor(R.color.bixue_red));
                    }
                }

            } else {//已完成
                tv_actualChLength.setText(100 + "%");
                tv_actualChLength.setTextColor(SubPreJobTrainingActivity.this.getResources().getColor(R.color.holetotal_gray));
            }


//            if(actualChLength==0)
//            {
//                tv_actualChLength.setText(" 0");
//            }else{
//                tv_actualChLength.setText(actualChLength+"");
//            }
//
//            if(setChLength==0)
//            {
//                tv_setChLength.setText("/"+"分钟");
//            }else{
//                tv_setChLength.setText("/"+setChLength+"分钟");
//            }

            if (rowsBean.getSpotCheckMark() == 1) {
                tv_Spotcheck.setText("通过抽查");
                tv_Spotcheck.setBackgroundResource(R.drawable.shape_specified_yes);
            } else if (rowsBean.getSpotCheckMark() == 2) {
                tv_Spotcheck.setText("未通过抽查");
                tv_Spotcheck.setBackgroundResource(R.drawable.shape_specified_nored);
            } else {
                tv_Spotcheck.setVisibility(View.INVISIBLE);
            }

            if (rowsBean.getCheckMark() == 2) {
                tv_check.setVisibility(View.VISIBLE);
                tv_check.setText("审核未通过");
                tv_check.setBackgroundResource(R.drawable.shape_specified_nored);
                tv_yes.setText("已完成");
                tv_line_specified.setBackgroundResource(R.color.specified_red);
                //  img_share.setVisibility(View.VISIBLE);
                tv_yes.setBackgroundResource(R.drawable.shape_specified_yes);
                tv_sign.setVisibility(View.VISIBLE);
                final String signPicUrl = HelpUtil.judgeStrNull(rowsBean.getSignPicUrl());
                if (signPicUrl.equals("")) {
                    tv_sign.setText("未签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_noorange);

                    tv_specified_learning.setText("签名");

                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                                    Context.MODE_PRIVATE);
                            int signMark = sp.getInt("signMark", 0);
                            int sn = rowsBean.getSn();
                            Bundle bundle = new Bundle();
                            bundle.putInt("sn", sn);
                            bundle.putString("signPicUrl", "");
                            if (signMark < 2) {
                                bundle.putInt("signMark", 1);
                            } else if (signMark == 2) {
                                bundle.putInt("signMark", 2);
                            }
                            startActivity(SignActivity.class, bundle);

                        }
                    });

                } else {
                    tv_sign.setText("已签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_yes);
                    tv_specified_learning.setText("查看签名");

                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }

                            SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                                    Context.MODE_PRIVATE);
                            int signMark = sp.getInt("signMark", 0);
                            int sn = rowsBean.getSn();
                            Bundle bundle = new Bundle();
                            bundle.putInt("sn", sn);
                            bundle.putString("signPicUrl", "");
                            if (signMark < 2) {
                                bundle.putInt("signMark", 1);
                            } else if (signMark == 2) {
                                bundle.putInt("signMark", 2);
                            }
                            bundle.putString("signPicUrl", signPicUrl);
                            startActivity(SignActivity.class, bundle);
                        }
                    });

                }
            } else if (rowsBean.getCheckMark() == 1) {
                //   img_share.setVisibility(View.VISIBLE);
                tv_check.setVisibility(View.GONE);
//                    tv_check.setText("审核通过");
//                    tv_check.setBackgroundResource(R.drawable.shape_specified_yes);
                tv_line_specified.setBackgroundResource(R.color.holetotal_gray);
                tv_yes.setText("已完成");
                tv_yes.setBackgroundResource(R.drawable.shape_specified_yes);
                tv_sign.setVisibility(View.VISIBLE);
                final String signPicUrl = HelpUtil.judgeStrNull(rowsBean.getSignPicUrl());
                if (signPicUrl.equals("")) {
                    tv_sign.setText("未签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_noorange);
                    tv_specified_learning.setText("签名");
                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                                    Context.MODE_PRIVATE);
                            int signMark = sp.getInt("signMark", 0);
                            int sn = rowsBean.getSn();
                            Bundle bundle = new Bundle();
                            bundle.putInt("sn", sn);
                            bundle.putString("signPicUrl", "");
                            if (signMark < 2) {
                                bundle.putInt("signMark", 1);
                            } else if (signMark == 2) {
                                bundle.putInt("signMark", 2);
                            }
                            startActivity(SignActivity.class, bundle);

                        }
                    });
                } else {
                    tv_sign.setText("已签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_yes);
                    tv_specified_learning.setText("查看签名");

                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }

                            SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                                    Context.MODE_PRIVATE);
                            int signMark = sp.getInt("signMark", 0);
                            int sn = rowsBean.getSn();
                            Bundle bundle = new Bundle();
                            bundle.putInt("sn", sn);
                            bundle.putString("signPicUrl", "");
                            if (signMark < 2) {
                                bundle.putInt("signMark", 1);
                            } else if (signMark == 2) {
                                bundle.putInt("signMark", 2);
                            }
                            bundle.putString("signPicUrl", signPicUrl);
                            startActivity(SignActivity.class, bundle);

                        }
                    });
                }
            } else if (rowsBean.getCheckMark() == 0) {


                if (rowsBean.getFinishMark() == 1) {
                    //  img_share.setVisibility(View.VISIBLE);
                    tv_yes.setText("已完成");
                    tv_yes.setBackgroundResource(R.drawable.shape_specified_yes);
                    tv_check.setVisibility(View.GONE);
//                        tv_check.setText("待审核");
//                        tv_check.setBackgroundResource(R.drawable.shape_specified_dai);
                    tv_line_specified.setBackgroundResource(R.color.holetotal_yellow);
                    tv_sign.setVisibility(View.VISIBLE);
                    tv_sign.setText("未签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_noorange);
                    tv_specified_learning.setText("签名");

                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                                    Context.MODE_PRIVATE);
                            int signMark = sp.getInt("signMark", 0);
                            int sn = rowsBean.getSn();
                            Bundle bundle = new Bundle();
                            bundle.putInt("sn", sn);
                            bundle.putString("signPicUrl", "");
                            if (signMark < 2) {
                                bundle.putInt("signMark", 1);
                            } else if (signMark == 2) {
                                bundle.putInt("signMark", 2);
                            }
                            startActivity(SignActivity.class, bundle);

                        }
                    });

                } else if (rowsBean.getFinishMark() == 2) {
                    //   img_share.setVisibility(View.VISIBLE);
                    tv_yes.setText("已完成");
                    tv_yes.setBackgroundResource(R.drawable.shape_specified_yes);
                    tv_check.setVisibility(View.GONE);
//                        tv_check.setText("待审核");
//                        tv_check.setBackgroundResource(R.drawable.shape_specified_dai);
                    tv_line_specified.setBackgroundResource(R.color.holetotal_yellow);
                    tv_sign.setVisibility(View.VISIBLE);
                    tv_sign.setText("已签名");
                    tv_sign.setBackgroundResource(R.drawable.shape_specified_yes);
                    tv_specified_learning.setText("查看签名");
                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                                    Context.MODE_PRIVATE);
                            int signMark = sp.getInt("signMark", 0);
                            int sn = rowsBean.getSn();
                            String signPicUrl = HelpUtil.judgeStrNull(rowsBean.getSignPicUrl());
                            Bundle bundle = new Bundle();
                            bundle.putInt("sn", sn);
                            bundle.putString("signPicUrl", signPicUrl);
                            if (signMark < 2) {
                                bundle.putInt("signMark", 1);
                            } else if (signMark == 2) {
                                bundle.putInt("signMark", 2);
                            }
                            startActivity(SignActivity.class, bundle);
                        }
                    });

                } else if (rowsBean.getFinishMark() == 0) {
                    //   img_share.setVisibility(View.INVISIBLE);
                    tv_yes.setText("未完成");
                    tv_yes.setBackgroundResource(R.drawable.shape_specified_nored);
                    tv_line_specified.setBackgroundResource(R.color.specified_red);
                    tv_check.setVisibility(View.GONE);
                    tv_sign.setVisibility(View.GONE);
                    tv_specified_learning.setText("学习");
                    tv_specified_learning.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isFastClicker()) {
                                return;
                            }
                            SharedPreferences sp = getSharedPreferences("SubPreJobTrainingActivity",
                                    Context.MODE_PRIVATE);
                            int Mark = sp.getInt("Mark", 0);
                            int pjtMinPer = sp.getInt("pjtMinPer", 0);
                            String orgId = sp.getString("orgId", "");
                            String forbidHour = sp.getString("forbidHour", "");
                            int faceRecgMark = sp.getInt("faceRecgMark", 0);
                            String photoUrl = sp.getString("photoUrl", "");
                            int signMark = sp.getInt("signMark", 0);
                            int sn = rowsBean.getSn();
                            int otpSn = HelpUtil.judgeIntNull(rowsBean.getOtpSn());
                            int actualChLength = rowsBean.getActualChLength();
                            int setChLength = 0;
                            setChLength=(rowsBean.getMiNo()>rowsBean.getSetChLength())?rowsBean.getMiNo():rowsBean.getSetChLength();
                            int checkMark = rowsBean.getCheckMark();
                            int finishMark = rowsBean.getFinishMark();
                            int chNo = rowsBean.getChNo();
                            Bundle bundle = new Bundle();
                            bundle.putInt("Mark", Mark);
                            bundle.putInt("pjtMinPer", pjtMinPer);
                            bundle.putString("orgId", orgId);
                            bundle.putInt("sn", sn);
                            bundle.putInt("otpSn", otpSn);
                            bundle.putString("chName", chName);
                            bundle.putString("forbidHour", forbidHour);
                            bundle.putInt("actualChLength", actualChLength);
                            bundle.putInt("setChLength", setChLength);
                            bundle.putInt("chNo", chNo);
                            bundle.putInt("signMark", signMark);
                            bundle.putInt("checkMark", checkMark);
                            bundle.putInt("finishMark", finishMark);
                            bundle.putInt("faceRecgMark", faceRecgMark);
                            bundle.putString("photoUrl", photoUrl);
                            startActivity(ChildPreJobTrainingActivity.class, bundle);
                        }
                    });

                }
            }
        }


    }

}
